<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'company-members-form',
	'enableAjaxValidation'=>false,
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model['member']); ?>

	<div class="row">
		<?php echo $form->labelEx($model['member'],'name'); ?>
		<?php echo $form->textField($model['member'],'type',array('size'=>15,'maxlength'=>25,'placeholder'=>'Position/Type')); ?>
		<?php echo $form->error($model['member'],'type'); ?>
		<?php echo $form->textField($model['member'],'name',array('size'=>25,'maxlength'=>50,'placeholder'=>'Name')); ?>
		<?php echo $form->error($model['member'],'name'); ?>	
	</div>
	
	<div class="row">
	<table class="group" cellpadding="0" cellspacing="0" border="0">
            	<thead>
            		<tr>
            			<td><?php echo CHtml::label("Tel No. - ".CHtml::link('Add','#',array('id'=>'add')), 'telephone'); ?></td>
            		</tr>
            	</thead>
            	<tbody>
			<?php foreach($model['contact'] as $i=>$item): ?>
				<tr>
					<td>
						<?php echo $form->DropDownList($item, "[$i]type", company_members_contacts::model()->teleType,array('style'=>'width:9em;')); ?>
						<?php echo $form->TextField($item,"[$i]ref",array('size'=>25,'maxlength'=>35,'numberOnly'=>1)); ?>
					</td>
                </tr>
            <?php endforeach; ?>
            	</tbody>
            </table>
	</div>
	
	<div class="row">
	<table class="group" cellpadding="0" cellspacing="0" border="0">
            	<thead>
            		<tr>
            			<td><?php echo CHtml::label("Tel No. - ".CHtml::link('Add','#',array('id'=>'add')), 'telephone'); ?></td>
            		</tr>
            	</thead>
            	<tbody>
			<?php foreach($model['email'] as $i=>$item): ?>
				<tr>
					<td>
						<?php echo $form->DropDownList($item, "[$i]type", company_members_email::model()->emailType,array('style'=>'width:9em;')); ?>
						<?php echo $form->TextField($item,"[$i]ref",array('size'=>25,'maxlength'=>35,'numberOnly'=>1)); ?>
					</td>
                </tr>
            <?php endforeach; ?>
            	</tbody>
            </table>
	</div>

	<div class="row buttons">
		<?php echo CHtml::submitButton($model['member']->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->

<?php
$cs = Yii::app()->getClientScript();
$showUrl = CHtml::normalizeUrl(array('company/view'));
$script =<<<EOD
$('a#add').click(function(){
	var table = $(this).parents('table');
	AddNewTableRow(table);
	return false;
});
$('div#contacts input[numberOnly=1]').live('keypress',function(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46) {
    	return false
    }
});
$('select').live('change',function(){
	if($(this).val() == "Others"){
		var html = "<input size='15' name='"+$(this).attr('name')+"' id='"+$(this).attr('id')+"' placeholder='Please specify' />";
		$(this).replaceWith(html);
	}
});
$.company_members_form={
	afterSubmit:function(data){
		if(data.id != '')
			window.location = '$showUrl?id='+data.id;
	}
}
$('#company-members-form input[type=submit]').click(function(){
	var companyForm = $.extend({}, $.simplelogform,$.company_members_form);
	companyForm.Submit($('#company-members-form'));	
	return false;
});
EOD;
$cs->registerScript('company#create',$script);
?>